#!/usr/bin/env python
#-*-encoding:utf-8-*-
'''
Created on 2015年6月24日

@author: chenyongbing
'''
import sys,os
#current_dir = os.path.dirname(__file__)
current_dir = os.path.split(os.path.realpath(__file__))[0]


import pyhs2
class HiveClient2(object):
    '''
    classdocs
    '''


    def __init__(self,host='localhost',port=10002,user='root',passwd='',db='default',authMechanism="PLAIN"):
        """
        create connection to hive server2
        """
        self.conn = pyhs2.connect(host=host,
                                  port=port,
                                  authMechanism=authMechanism,
                                  user=user,
                                  password=passwd,
                                  database=db,
                                  )
    
    def execute(self,query):
        cursor = self.conn.cursor()
        cursor.execute(query)
        return cursor.fetchall()
    
    def SelectAll(self,query):
        cursor = self.conn.cursor()
        cursor.execute(query)
        return cursor.fetchall()
    def SelectOne(self,query):
        cursor = self.conn.cursor()
        cursor.execute(query)
        return cursor.fetchone()
    
    def SelectCount(self,query):
        cursor = self.conn.cursor()
        cursor.execute(query)
        return len(cursor.fetchall())
     
if __name__ == '__main__':
    myHiveClient = HiveClient2(host='192.168.1.201')
    query =  'select mac,day from history_role_test where day="2015-01-02" and role in (1,-1,3,10) limit 10'
    print myHiveClient.SelectCount(query)
    